$(function () {
    function sendAjax(num){


        $.get("/lession05/getList", { page: num, count: 32 }, function (data) {
            let str = ``
            data.data.forEach(function (value, index) {
                str += `
                <div class="card col-3">
                    <img src="${value.goods_small_logo}" class="card-img-top" alt="...">
                    <div class="card-body">
                        <h5 class="card-title text-danger">￥${value.goods_price}</h5>
                        <p class="card-text text-truncate">${value.goods_name}</p>
                        <a href="/html/detail.html?id=${value.goods_id}" class="btn btn-primary">查看详情</a>
                        </div>
                    </div>
                </div>
                `
            })
            $("#list").html(str)
        })
    }
    sendAjax(0)

    $('.page-test').page({
        leng: 23,//分页总数
        activeClass: 'activeA', //active 类样式定义
        clickBack: function (page) {
          // 点击数字 下一页 首页 末页的时候执行的代码
          console.log("当前是第" + page + "页")
          sendAjax(page - 1)
    
          history.pushState(page, "", "/xunide#" + page)
        }
        , back() {
          history.back()
        }
      })


      window.onpopstate = function (e) {
        console.log(e.state)
        sendAjax(e.state - 1)
        $(".pagingUl li").each(function () {
          $(this).children().removeClass("active")
          if ($(this).children().html() == e.state) {
            $(this).children().addClass("active")
          }
        })
    
      }
    

})